---
title: "Replication File SF R&R 9 10 23"
output: html_document
date: "2023-09-11"
---

```{r}
library(tidyverse)
library(lfe)
library(did)
library(sp)
library(raster)
library(sf)
library(stargazer)
library(xtable)
library(fixest)
library(tmap)
options("scipen"=100, "digits"=2)
#setwd("")

```

# read in and clean data
TREATMENT & OUTCOMES
```{r}

# TREATMENT
treatment_10 <- sf::read_sf("replication_data_sf/blocks_wards_merged/blocks_wards_merged.shp") 

treat_10 <- as.data.frame(treatment_10@data) %>%
  dplyr::select(geoid10 = GEOID10, ward2015, ward2005) %>%
  mutate(dyn_l_15 = ifelse(ward2005 %in% c(6, 13, 14, 21, 26, 33, 34,  39, 40, 48, 50) & 
                             !ward2015 %in% c(6,  13, 14, 21,  26, 33, 34, 39, 40, 48, 50), 1, 0),
        dyn_g_15 = ifelse(!ward2005 %in% c(6, 13, 14, 21, 26, 33, 34,  39, 40, 48, 50) 
                           & ward2015 %in% c(6,  13, 14, 21,  26, 33, 34, 39, 40, 48, 50), 1, 0),
        dyn_change = ifelse(ward2005 %in% c(7, 11, 24, 38) 
                           | ward2015 %in% c(7, 11, 24, 38), 1, 0), 
        dyn_const = ifelse(ward2005 %in% c(6, 13, 14, 21, 26, 33, 34,  39, 40, 48, 50) 
                           & ward2015 %in% c(6,  13, 14, 21,  26, 33, 34, 39, 40, 48, 50), 1, 0),
        commit_gain_2015 = ifelse(!ward2005 %in% c(9, 11, 12, 14, 17, 23,  25, 27, 
                                                31, 33, 34,37, 39,  40, 44,49) &
                               ward2015 %in% c(1, 3,8,  9,12,   14,  21, 23, 25,  
                                               27, 30, 34, 37, 40, 44, 49), 1, 0),
        commit_loss_2015 = ifelse(ward2005 %in% c(9, 11, 12, 14, 17, 23,  25, 27, 
                                                31, 33, 34,37, 39,  40, 44,49) &
                               !ward2015 %in% c(1, 3,8,  9,12,   14,  21, 23, 25,  
                                               27, 30, 34, 37, 40, 44, 49), 1, 0),
        commit_const = ifelse(ward2005 %in% c(9, 11, 12, 14, 17, 23,  25, 27, 
                                                31, 33, 34,37, 39,  40, 44,49) &
                               ward2015 %in% c(1, 3,8,  9,12,   14,  21, 23, 25,  
                                               27, 30, 34, 37, 40, 44, 49), 1, 0),
        geoid10 = as.numeric(geoid10))


# OUTCOMES
outcome_data <- read_csv("replication_data_sf/Outcome_Yearly_03_29_22.csv") %>%
  dplyr::select(geoid10 = GEOID10, year,
                duration_ph:duration1_phW,
                sr_311D:duration_medianND) %>%
  mutate(sr_no_super = sr_311D - n_dupD,
         srND_no_super = sr_311ND - n_dupND)


```

CONTROLS
```{r}
# block-group demographic data
import_socexp <- function(x) {
  read_csv(x) %>%
    dplyr::select(geoid_bgrp = Geo_FIPS, 
                tot_pop = SE_A00001_001,  
                male = SE_A02001_002, female = SE_A02001_003,
         white_non_hisp = SE_A04001_003, black  = SE_A03001_003, 
         native  = SE_A03001_004,asian  = SE_A03001_005, 
         pac_isl  = SE_A03001_006, other_race  = SE_A03001_007, 
         hispanic  = SE_A04001_010, occupied  = SE_A10044_002, 
         housing_units  = SE_A10044_001, vacant  = SE_A10044_003, 
         pop18_over  = SE_A01001B_005, unemployed = SE_A17005_003,
         # held constant at $2011
         med_inc = SE_A14006_001, ba_or_more = SE_A12002_005) %>%
  mutate(file = x)
}

# create a list of files
files <- dir("replication_data_sf/bgrp_demo_data", pattern="\\.csv$", full.names=TRUE)


# created the object to which i'll pass the loop
bgrp_demo <- vector("list", length(files))
 # the range of files are the list i created above
for(fname in seq_along(files)) {
  # using my import function
  bgrp_demo[[fname]] <- import_socexp(files[[fname]])
  }

bgrp_demo_11_18 <- bgrp_demo %>%
  bind_rows() %>%
  separate(file, sep = -4, into = c("year", "ext")) %>%
  separate(year, sep = -4, into = c("file", "year"), convert = TRUE) %>%
  dplyr::select(-ext, -file)


block_demo_10 <- read_csv("replication_data_sf/se_block_2010.csv") %>%
    dplyr::select(geoid10 = Geo_FIPS, tot_pop= SE_T001_001,
                male = SE_T003_002, female = SE_T003_003,
         white_non_hisp = SE_T055_003, black  = SE_T054_003, 
         native  = SE_T054_004, asian  = SE_T054_005, 
         pac_isl  = SE_T054_006, other_race  = SE_T054_007, 
         hispanic  = SE_T055_010, occupied  = SE_T070_002, 
         vacant  = SE_T070_003, housing_units = SE_T070_001,
         pop18_over  = SE_T012B005) %>%
  # these are not mutually exclusive, in a few places, a block might be 50/50; 
  # also happens because we're pulling in black (including hispanic) vs white (not including hispanic)
  mutate(asian_pct = (asian/tot_pop)*100,
         asian_pct =  ifelse(tot_pop == 0, 0, asian_pct),
         black_pct = (black/tot_pop)*100,
         black_pct =  ifelse(tot_pop == 0, 0, black_pct),
         hisp_pct = (hispanic/tot_pop)*100,
         hisp_pct =  ifelse(tot_pop == 0, 0, hisp_pct),
         white_pct = (white_non_hisp/tot_pop)*100,
         white_pct =  ifelse(tot_pop == 0, 0, white_pct),
         maj_white_block = ifelse(tot_pop ==0, 0,
                                  ifelse(white_pct >= 50, 1, 0)),
         maj_black_block = ifelse(tot_pop ==0, 0,
                                  ifelse(black_pct >= 50, 1, 0)),
         maj_hisp_block = ifelse(tot_pop ==0, 0,
                                  ifelse(hisp_pct >= 50, 1, 0)),
         maj_asian_block = ifelse(tot_pop ==0, 0,
                                  ifelse(asian_pct >= 50, 1, 0)))

# 2010 demo data; 2015 ward boundaries
race_match2015 <- treat_10 %>%
  left_join(block_demo_10, by = "geoid10")  %>%
  group_by(ward2015) %>%
  mutate(ward_pop15 = sum(tot_pop, na.rm = TRUE),
         ward_black15 = sum(black, na.rm = TRUE),
         ward_hispanic15 = sum(hispanic, na.rm = TRUE),
         ward_asian15 = sum(asian, na.rm = TRUE),
         ward_white15 = sum(white_non_hisp, na.rm = TRUE),
         ward_black_pct15 = (ward_black15/ward_pop15)*100,
         ward_hisp_pct15 = (ward_hispanic15/ward_pop15)*100,
         ward_asian_pct15 = (ward_asian15/ward_pop15)*100,
         ward_white_pct15 = (ward_white15/ward_pop15)*100) %>%
  ungroup() %>%
  mutate(maj_black_ward15 = ifelse(ward_black_pct15 >= 50, 1, 0),
         maj_hisp_ward15 = ifelse(ward_hisp_pct15 >= 50, 1, 0),
         maj_asian_ward15 = ifelse(ward_asian_pct15 >= 50, 1, 0),
         maj_white_ward15 = ifelse(ward_white_pct15 >= 50, 1, 0)) %>%
  mutate(race_match15 = ifelse(maj_white_block == 1 & maj_white_ward15 == 1, 1,
                             ifelse(maj_black_block == 1 & maj_black_ward15 == 1, 1,
                             ifelse(maj_hisp_block == 1 & maj_hisp_ward15 == 1, 1,
                             ifelse(maj_asian_block == 1 & maj_asian_ward15 == 1, 1,
                             ifelse(tot_pop == 0, 0, 0))))),
         asian_match15 = ifelse(maj_asian_block == 1 & maj_asian_ward15 == 1, 1, 0),
         hisp_match15 = ifelse(maj_hisp_block == 1 & maj_hisp_ward15 == 1, 1, 0),
         black_match15 = ifelse(maj_black_block == 1 & maj_black_ward15 == 1, 1, 0),
         white_match15 = ifelse(maj_white_block == 1 & maj_white_ward15 == 1, 1, 0)) %>%
  dplyr::select(geoid10, race_match15:white_match15) %>%
  distinct(geoid10, .keep_all = TRUE)

# 2005 boundaries
race_match2005 <- treat_10 %>%
  left_join(block_demo_10, by = "geoid10")  %>%
  group_by(ward2005) %>%
  mutate(ward_pop05  = sum(tot_pop, na.rm = TRUE),
         ward_black05  = sum(black, na.rm = TRUE),
         ward_hispanic05  = sum(hispanic, na.rm = TRUE),
         ward_asian05  = sum(asian, na.rm = TRUE),
         ward_white05 = sum(white_non_hisp, na.rm = TRUE),
         ward_black_pct05 = (ward_black05/ward_pop05)*100,
         ward_hisp_pct05 = (ward_hispanic05/ward_pop05)*100,
         ward_asian_pct05 = (ward_asian05/ward_pop05)*100,
         ward_white_pct05 = (ward_white05/ward_pop05)*100) %>%
  ungroup() %>%
  mutate(maj_black_ward05 = ifelse(ward_black_pct05 >= 50, 1, 0),
         maj_hisp_ward05 = ifelse(ward_hisp_pct05 >= 50, 1, 0),
         maj_asian_ward05 = ifelse(ward_asian_pct05 >= 50, 1, 0),
         maj_white_ward05 = ifelse(ward_white_pct05 >= 50, 1, 0)) %>%
  mutate(race_match05 = ifelse(maj_white_block == 1 & maj_white_ward05 == 1, 1,
                             ifelse(maj_black_block == 1 & maj_black_ward05 == 1, 1,
                             ifelse(maj_hisp_block == 1 & maj_hisp_ward05 == 1, 1,
                             ifelse(maj_asian_block == 1 & maj_asian_ward05 == 1, 1,
                             ifelse(tot_pop == 0, 0, 0))))),
         asian_match05 = ifelse(maj_asian_block == 1 & maj_asian_ward05 == 1, 1, 0),
         hisp_match05 = ifelse(maj_hisp_block == 1 & maj_hisp_ward05 == 1, 1, 0),
         black_match05 = ifelse(maj_black_block == 1 & maj_black_ward05 == 1, 1, 0),
         white_match05 = ifelse(maj_white_block == 1 & maj_white_ward05 == 1, 1, 0)) %>%
  dplyr::select(geoid10, race_match05:white_match05) %>%
  distinct(geoid10, .keep_all = TRUE)



# extract the block group identifier from blocks to have a block-group -> block key
blkgrp2010 <- treat_10 %>%
  # create another column, geoid_bgrp, 
  # which will be the block group geoid, to merge with demo data
  mutate(geoid_bgrp = geoid10) %>%
  separate(geoid_bgrp, into = c("geoid_bgrp", "extra"), sep = -3) %>%
  mutate(geoid_bgrp = as.numeric(geoid_bgrp)) %>%
  dplyr::select(geoid10, geoid_bgrp)
```

FULL DATA
```{r}

full_data_11_18 <- outcome_data %>%
  left_join(treat_10, by = "geoid10") %>%
  left_join(blkgrp2010, by = "geoid10") %>%
  left_join(bgrp_demo_11_18, by =c("geoid_bgrp", "year")) %>%
  left_join(race_match2005, by = "geoid10")%>%
  left_join(race_match2015, by = "geoid10") %>%
  mutate(dyn_gain = ifelse(year >= 2015 & dyn_g_15 == 1 & dyn_l_15 != 1, 1, 
                           ifelse(dyn_l_15 ==1, NA, 0)),
         dyn_loss = ifelse(year >= 2015 & dyn_l_15 == 1 & dyn_g_15 != 1, 1, 
                           ifelse(dyn_g_15 == 1, NA, 0)),
         redistrict15 = ifelse(year >= 2015 & ward2005 != ward2015, 1, 0),
         dyn_g_15_na = ifelse(dyn_l_15 == 1, NA, 
                            ifelse(dyn_const == 1, NA, dyn_g_15)),
         dyn_l_15_na = ifelse(dyn_g_15 == 1, NA, 
                              ifelse(dyn_const == 1, NA,dyn_l_15)),
         commit_gain = ifelse(year >= 2015 & commit_gain_2015 == 1 & commit_loss_2015 != 1, 1, 
                           ifelse(commit_loss_2015 ==1, NA, 0)),
         commit_g_15_na = ifelse(commit_loss_2015 == 1, NA, 
                            ifelse(commit_const == 1, NA, commit_gain_2015)),
         ward2005 = as.numeric(ward2005),
         ward2015 = as.numeric(ward2015),
         dyn_ward = ifelse(ward2005 %in% c(14, 21, 33, 34, 39, 40) & year <= 2014, 1, 
                           ifelse(ward2015 %in% c(14, 21, 33, 34, 39, 40) & year >= 2015, 1, 0)),
         race_match = ifelse(race_match05 == 1 & year < 2015, 1,
                             ifelse(race_match15 ==1 & year >=2015, 1, 
                                    ifelse(race_match05 == 0 & year < 2015, 0,
                                    ifelse(race_match15 == 0 & year >= 2015, 0, NA)))),
         asian_match = ifelse(asian_match05 == 1 & year < 2015, 1,
                             ifelse(asian_match15 ==1 & year >=2015, 1, 
                                    ifelse(asian_match05 == 0 & year < 2015, 0,
                                    ifelse(asian_match15 == 0 & year >= 2015, 0, NA)))),
         black_match = ifelse(black_match05 == 1 & year < 2015, 1,
                             ifelse(black_match15 ==1 & year >=2015, 1, 
                                    ifelse(black_match05 == 0 & year < 2015, 0,
                                    ifelse(black_match15 == 0 & year >= 2015, 0, NA)))),
         hisp_match = ifelse(hisp_match05 == 1 & year < 2015, 1,
                             ifelse(hisp_match15 ==1 & year >=2015, 1, 
                                    ifelse(hisp_match05 == 0 & year < 2015, 0,
                                    ifelse(hisp_match15 == 0 & year >= 2015, 0, NA)))),
         white_match = ifelse(white_match05 == 1 & year < 2015, 1,
                             ifelse(white_match15 ==1 & year >=2015, 1, 
                                    ifelse(white_match05 == 0 & year < 2015, 0,
                                    ifelse(white_match15 == 0 & year >= 2015, 0, NA)))),
         asian_pct = (asian/tot_pop)*100,
         asian_pct =  ifelse(tot_pop == 0, 0, asian_pct),
         black_pct = (black/tot_pop)*100,
         black_pct =  ifelse(tot_pop == 0, 0, black_pct),
         hispanic_pct = (hispanic/tot_pop)*100,
         hispanic_pct =  ifelse(tot_pop == 0, 0, hispanic_pct),
         white_pct = (white_non_hisp/tot_pop)*100,
         white_pct =  ifelse(tot_pop == 0, 0, white_pct),
         femal_pct = (female/tot_pop)*100,
         femal_pct =  ifelse(tot_pop == 0, 0, femal_pct),
         ba_pct = (ba_or_more/tot_pop)*100,
         ba_pct =  ifelse(tot_pop == 0, 0, ba_pct),
         unemp_pct = (unemployed/pop18_over)*100,
         unemp_pct =  ifelse(pop18_over == 0, 0, unemp_pct),
         pop18_over_pct = (pop18_over/tot_pop)*100,
         pop18_over_pct =  ifelse(tot_pop == 0, 0, pop18_over_pct),
         nonpop_dummy= 0, 
         nonpop_dummy= ifelse(tot_pop==0, 1, nonpop_dummy),
         year_2011 = ifelse(year == 2011, 1, 0),
         year_2012 = ifelse(year == 2012, 1, 0),
         year_2013 = ifelse(year == 2013, 1, 0),
         year_2014 = ifelse(year == 2014, 1, 0),
         year_2015 = ifelse(year == 2015, 1, 0),
         year_2016 = ifelse(year == 2016, 1, 0),
         year_2017 = ifelse(year == 2017, 1, 0),
         year_2018 = ifelse(year == 2018, 1, 0)) %>%
  
  # we want to keep in the 17 blocks that were redistricted from one dynastic ward to another as "constant"
  # so if you filter const_treat_only != 1, you get only the dyn_constants + others, none of the dyn_loss and gain blocks
  mutate(const_treat_only = ifelse(dyn_g_15 == 1 & dyn_l_15 == 0, 1, 
                          ifelse(dyn_l_15 == 1 & dyn_g_15 == 0, 1, 
                                 ifelse(dyn_g_15 == 1 & dyn_l_15 == 1, 0, 0)))) %>%
  # filter out blocks that are on the edge of chicago, whose centroids are not in city limits
  filter(!is.na(ward2005), !is.na(ward2015))



```

# Main Text
Figure 1. dynastic ward boundaries -  need to redo for all 11 wards

Figure 2. Committe Memberships
```{r}

commmittee_data <- read_csv("replication_data_sf/committees_table_data.csv") %>%
  mutate(Ward = ifelse(grepl("austin", person), "Austin, 34", 
                       ifelse(grepl("brookins", person), "Brookins, 21", 
                       ifelse(grepl("burke", person), "Burke, 14", 
                       ifelse(grepl("o'connor", person), "O'Connor, 40", 
                       ifelse(grepl("laurino", person), "Laurino, 39",  
                       ifelse(grepl("mell", person), "Mell, 33", "non-dynastic")))))),
         Committee = ifelse(grepl("budget", committee), "Budget", 
                       ifelse(grepl("economic", committee), "Economic, capital, and technology development", 
                       ifelse(grepl("education", committee), "Education", 
                       ifelse(grepl("finance", committee), "Finance", 
                       ifelse(grepl("pedestrian", committee), "Pedestrian & traffic",  
                       ifelse(grepl("rules", committee), "Rules", 
                       ifelse(grepl("workforce", committee), "Workforce development & audit", "non-dynastic ward")))))))) %>%
  filter(Ward != "non-dynastic") 


figure_2 <- commmittee_data %>%
  ggplot(aes(year, amount, fill = Committee)) +
  geom_bar(stat = "identity") +
  facet_wrap(~Ward) +
  theme_bw() +
  scale_fill_grey() +
  labs(x ="Year", y = "Amount") +
  theme(axis.text.x = element_text(angle = 45, vjust = 0.5),
        text=element_text(family="Times", size=12))
ggsave("results_rr_2/figure_2.pdf", dpi = 350)
```


Figure 3. quasi-experimental research design

annualized figures, in-text
```{r}

full_data_11_18 %>%
 # group_by(year) %>%
  summarize(homicide = mean(homicide),
            assault = mean(assault),
            robbery = mean(robbery),
            theft = mean(theft),
            potholes = mean(pothole_filledND))

```

Table 1. OLS Regression of Crime & City Services on Block Membership in Dynastic vs. Non-Dynastic Wards, 2011-2018
```{r}

# CITY SERVICES

potholes_ols <- felm(pothole_filledD ~ dyn_const + tot_pop + black_pct + hispanic_pct + white_pct +asian_pct +
                             nonpop_dummy+femal_pct+  pop18_over_pct  + unemp_pct + occupied + ba_pct + med_inc +
                        black_match + hisp_match + white_match +
                        redistrict15  | 
                             year  | 0  | geoid10,
                   data = filter(full_data_11_18, dyn_g_15 != 1, dyn_l_15 != 1))

homicide_ols <- felm(homicide ~ dyn_const + tot_pop + black_pct + hispanic_pct + white_pct +asian_pct +
                             nonpop_dummy+femal_pct+  pop18_over_pct  + unemp_pct + occupied + ba_pct + med_inc +
                        black_match + hisp_match + white_match +
                        redistrict15  | 
                             year   | 0  | geoid10,
                   data = filter(full_data_11_18, dyn_g_15 != 1, dyn_l_15 != 1))
assault_ols <- felm(assault ~ dyn_const + tot_pop + black_pct + hispanic_pct + white_pct +asian_pct +
                             nonpop_dummy+femal_pct+  pop18_over_pct  + unemp_pct + occupied + ba_pct + med_inc +
                        black_match + hisp_match + white_match +
                        redistrict15  | 
                             year   | 0  | geoid10,
                   data = filter(full_data_11_18, dyn_g_15 != 1, dyn_l_15 != 1))
rob_ols <- felm(robbery ~ dyn_const + tot_pop + black_pct + hispanic_pct + white_pct +asian_pct +
                             nonpop_dummy+femal_pct+  pop18_over_pct  + unemp_pct + occupied + ba_pct + med_inc +
                        black_match + hisp_match + white_match +
                        redistrict15  | 
                             year  | 0  | geoid10,
                   data = filter(full_data_11_18, dyn_g_15 != 1, dyn_l_15 != 1))
theft_ols <- felm(theft ~ dyn_const + tot_pop + black_pct + hispanic_pct + white_pct +asian_pct +
                             nonpop_dummy+femal_pct+  pop18_over_pct  + unemp_pct + occupied + ba_pct + med_inc +
                        black_match + hisp_match + white_match +
                        redistrict15  | 
                             year   | 0  | geoid10,
                   data = filter(full_data_11_18, dyn_g_15 != 1, dyn_l_15 != 1))


# Table 1RR/S3
stargazer(potholes_ols, homicide_ols, assault_ols, rob_ols, theft_ols,
          star.cutoffs = c(0.05, 0.01, 0.001), omit.stat=c("LL","ser","f"), 
          ci=TRUE, ci.level=0.95, single.row=FALSE,
           covariate.labels = c( "Dynastic Ward" ),
           add.lines = list( c( "Year FEs", "Yes", "Yes", "Yes", "Yes" , "Yes"),
                             c( "Covariates", "Yes", "Yes", "Yes", "Yes" , "Yes") ),
           omit = c( "tot_pop", "black_pct", "hispanic_pct",  "white_pct" , "asian_pct" , 
                             "nonpop_dummy", "femal_pct", "occupied" ,  "pop18_over_pct"  ,  "unemp_pct" ,  
                        "black_match" ,  "hisp_match" ,  "white_match" , 
                        "redistrict15" , "ba_pct" , "med_inc") )


```

Figure 4. Annexation into Dynastic Wards (no covariates)
```{r}

event_study_data <- full_data_11_18 %>%
  filter(dyn_const != 1, dyn_l_15 != 1) %>%
  mutate(year_1 = year-2010) %>%
  rename(Year = year, Annexation = dyn_g_15)

# SERVICES

pot_es1 = feols(pothole_filledD ~ i(year_1, Annexation, ref = 4) | 
                             year_1 + geoid10 ,                             ## FEs
		 cluster = ~geoid10,                          ## Clustered SEs
		 data = event_study_data)

#pdf("results_rr_2/pot_plot_gain_nocv.pdf")
tiff("results_rr_2/pot_plot_gain_nocv.tiff", width = 4, height = 4, units = 'in', res = 350)
iplot(pot_es1, 
      xlab = 'Year',
      main = '')
dev.off()


hom_es1 = feols(homicide ~ i(year_1, Annexation, ref = 4) | 
                             year_1 + geoid10 ,                             ## FEs
		 cluster = ~geoid10,                          ## Clustered SEs
		 data = event_study_data)

#pdf("results_rr_2/hom_plot_gain_nocv.pdf")
tiff("results_rr_2/hom_plot_gain_nocv.tiff", width = 4, height = 4, units = 'in', res = 350)
hom_es1 %>%
  iplot(xlab = 'Year',
      main = '')
dev.off()


assault_es1 = feols(assault ~ i(year_1, Annexation, ref = 4)| 
                             year_1 + geoid10 ,                             ## FEs
		 cluster = ~geoid10,                          ## Clustered SEs
		 data = event_study_data)


#pdf("results_rr_2/assault_plot_gain_nocv.pdf")
tiff("results_rr_2/assault_plot_gain_nocv.tiff", width = 4, height = 4, units = 'in', res = 350)
iplot(assault_es1, 
      xlab = 'Year',
      main = '')
dev.off()

rob_es1 = feols(robbery ~ i(year_1, Annexation, ref = 4)| 
                             year_1 + geoid10 ,                             ## FEs
		 cluster = ~geoid10,                          ## Clustered SEs
		 data = event_study_data)


#pdf("results_rr_2/rob_plot_gain_nocv.pdf")
tiff("results_rr_2/rob_plot_gain_nocv.tiff", width = 4, height = 4, units = 'in', res = 350)
iplot(rob_es1, 
      xlab = 'Year',
      main = '')
dev.off()


theft_es1 = feols(theft ~ i(year_1, Annexation, ref = 4) | 
                             year_1 + geoid10 ,                             ## FEs
		 cluster = ~geoid10,                          ## Clustered SEs
		 data = event_study_data)

#pdf("results_rr_2/theft_plot_gain_nocv.pdf")
tiff("results_rr_2/theft_plot_gain_nocv.tiff", width = 4, height = 4, units = 'in', res = 350)
iplot(theft_es1, 
      xlab = 'Year',
      main = '')
dev.off()



```
                      
Figure 5. Annexation into Committee Chair Positions
```{r}


event_study_data2 <- full_data_11_18 %>%
  filter(commit_const != 1, commit_loss_2015 != 1) %>%
  mutate(year_1 = year-2010) %>%
  rename(Year = year, Annexation = commit_gain_2015)

# SERVICES

pot_es_commit = feols(pothole_filledD ~ i(year_1, Annexation, ref = 4) | 
                             year_1 + geoid10 ,                             ## FEs
		 cluster = ~geoid10,                          ## Clustered SEs
		 data = event_study_data2)

#pdf("results_rr_2/pot_plot_gain_commit.pdf")
tiff("results_rr_2/pot_plot_gain_commit.tiff", width = 4, height = 4, units = 'in', res = 350)
iplot(pot_es_commit, 
      xlab = 'Year',
      main = '')
dev.off()


hom_es_commit = feols(homicide ~ i(year_1, Annexation, ref = 4)  | 
                             year_1 + geoid10 ,                             ## FEs
		 cluster = ~geoid10,                          ## Clustered SEs
		 data = event_study_data2)

#pdf("results_rr_2/hom_plot_gain_commit.pdf")
tiff("results_rr_2/hom_plot_gain_commit.tiff", width = 4, height = 4, units = 'in', res = 350)
hom_es_commit %>%
  iplot(xlab = 'Year',
      main = '')
dev.off()


assault_es_commit = feols(assault ~ i(year_1, Annexation, ref = 4) | 
                             year_1 + geoid10 ,                             ## FEs
		 cluster = ~geoid10,                          ## Clustered SEs
		 data = event_study_data2)


#pdf("results_rr_2/assault_plot_gain_commit.pdf")
tiff("results_rr_2/assault_plot_gain_commit.tiff", width = 4, height = 4, units = 'in', res = 350)
iplot(assault_es_commit, 
      xlab = 'Year',
      main = '')
dev.off()

rob_es_commit = feols(robbery ~ i(year_1, Annexation, ref = 4) | 
                             year_1 + geoid10 ,                             ## FEs
		 cluster = ~geoid10,                          ## Clustered SEs
		 data = event_study_data2)


#pdf("results_rr_2/rob_plot_gain_commit.pdf")
tiff("results_rr_2/rob_plot_gain_commit.tiff", width = 4, height = 4, units = 'in', res = 350)
iplot(rob_es_commit, 
      xlab = 'Year',
      main = '')
dev.off()


theft_es_commit = feols(theft ~ i(year_1, Annexation, ref = 4) | 
                             year_1 + geoid10 ,                             ## FEs
		 cluster = ~geoid10,                          ## Clustered SEs
		 data = event_study_data2)

#pdf("results_rr_2/theft_plot_gain_commit.pdf")
tiff("results_rr_2/theft_plot_gain_commit.tiff", width = 4, height = 4, units = 'in', res = 350)
iplot(theft_es_commit, 
      xlab = 'Year',
      main = '')
dev.off()


# wald tests
wald(pot_es_commit, "year_1::[123]")
wald(hom_es_commit, "year_1::[123]")
wald(assault_es_commit, "year_1::[123]")
wald(rob_es_commit, "year_1::[123]")
wald(theft_es_commit, "year_1::[123]")

```

Table 2. Mechanisms 
```{r}

sr_gaina <- felm(sr_311D ~ year_2011:dyn_g_15 + year_2012:dyn_g_15 + 
                         year_2013:dyn_g_15 + year_2015:dyn_g_15 + 
                         year_2016:dyn_g_15 + 
                             year_2017:dyn_g_15 + 
                             year_2018:dyn_g_15 + tot_pop + black_pct + hispanic_pct + white_pct +asian_pct +
                             nonpop_dummy+femal_pct+  pop18_over_pct  + unemp_pct + occupied + ba_pct + med_inc +
                        black_match + hisp_match + white_match +
                        redistrict15  | 
                           year + geoid10 | 0  | geoid10,
                   data = filter(full_data_11_18, dyn_const != 1, dyn_l_15 != 1))

sr_gainb <- felm(sr_no_super ~ year_2011:dyn_g_15 + year_2012:dyn_g_15 + 
                         year_2013:dyn_g_15 + year_2015:dyn_g_15 + 
                         year_2016:dyn_g_15 + 
                             year_2017:dyn_g_15 + 
                             year_2018:dyn_g_15 + tot_pop + black_pct + hispanic_pct + white_pct +asian_pct +
                             nonpop_dummy+femal_pct+  pop18_over_pct  + unemp_pct + occupied + ba_pct + med_inc +
                        black_match + hisp_match + white_match +
                        redistrict15  | 
                           year + geoid10 | 0  | geoid10,
                   data = filter(full_data_11_18, dyn_const != 1, dyn_l_15 != 1))

sr_dups_gain <- felm(n_status_dupD ~ year_2011:dyn_g_15 + year_2012:dyn_g_15 + 
                         year_2013:dyn_g_15 + year_2015:dyn_g_15 + 
                         year_2016:dyn_g_15 + 
                             year_2017:dyn_g_15 + 
                             year_2018:dyn_g_15 + tot_pop + black_pct + hispanic_pct + white_pct +asian_pct +
                             nonpop_dummy+femal_pct+  pop18_over_pct  + unemp_pct + occupied + ba_pct + med_inc +
                        black_match + hisp_match + white_match +
                        redistrict15  | 
                           year + geoid10 | 0  | geoid10,
                   data = filter(full_data_11_18, dyn_const != 1, dyn_l_15 != 1))



stargazer(sr_gaina, sr_gainb, sr_dups_gain,
          star.cutoffs = c(0.05, 0.01, 0.001), omit.stat=c("LL","ser","f"), 
          ci=TRUE, ci.level=0.95, single.row=FALSE,
           covariate.labels = c( "Total Population", "% Black", "% Hispanic",  "% White" , "% Asian" , 
                              "% Female",  "% Pop Over 18"  ,  "% Unemployed Over 18" , "No. Occupied Buildings" , 
                             "% College Educated" , "Median Income",  
                        "Maj. Black Block Redistricted into Maj. Black Ward " ,  "Maj. Hispanic Block Redistricted into Maj. Hispanic Ward " ,  
                        "Maj. White Block Redistricted into Maj. White Ward" , 
                        "Redistricted in 2015", "Annexation x 2011",  "Annexation x 2012", "Annexation x 2013",
                        "Dynasty Effect 2015", "Dynasty Effect 2016", "Dynasty Effect 2017", "Dynasty Effect 2018"),
           add.lines = list( c( "Year & Block FEs", "Yes", "Yes", "Yes", "Yes" , "Yes"),
                             c( "Time-Varying Covariates", "Yes", "Yes", "Yes", "Yes" , "Yes") ,
                             c( "Evidence of Pre-Trends, based on Wald Test", "No", "No", "No", "Yes" , "Yes") ),
           omit = c( "nonpop_dummy") )


sr_gaina = feols(sr_311D ~ i(year_1, Annexation, ref = 4) + tot_pop + black_pct + hispanic_pct + white_pct +asian_pct +
                             nonpop_dummy+femal_pct+  pop18_over_pct  + unemp_pct + occupied + ba_pct + med_inc +
                        black_match + hisp_match + white_match +
                        redistrict15 |
                             year_1 + geoid10 ,                             ## FEs
		 cluster = ~geoid10,                          ## Clustered SEs
		 data = event_study_data)
sr_gainb = feols(sr_no_super ~ i(year_1, Annexation, ref = 4)+ tot_pop + black_pct + hispanic_pct + white_pct +asian_pct +
                             nonpop_dummy+femal_pct+  pop18_over_pct  + unemp_pct + occupied + ba_pct + med_inc +
                        black_match + hisp_match + white_match +
                        redistrict15 |
                             year_1 + geoid10 ,                             ## FEs
		 cluster = ~geoid10,                          ## Clustered SEs
		 data = event_study_data)
sr_gainc = feols(n_status_dupD ~ i(year_1, Annexation, ref = 4)+ tot_pop + black_pct + hispanic_pct + white_pct +asian_pct +
                             nonpop_dummy+femal_pct+  pop18_over_pct  + unemp_pct + occupied + ba_pct + med_inc +
                        black_match + hisp_match + white_match +
                        redistrict15 |
                             year_1 + geoid10 ,                             ## FEs
		 cluster = ~geoid10,                          ## Clustered SEs
		 data = event_study_data)

iplot(sr_gaina, 
      xlab = 'Year',
      main = '')
iplot(sr_gainb, 
      xlab = 'Year',
      main = '')
iplot(sr_gainc, 
      xlab = 'Year',
      main = '')

# wald tests
wald(sr_gaina, "year_1::[123]")
wald(sr_gainb, "year_1::[123]")
wald(sr_gainc, "year_1::[123]")
```

Table 3. Comparison between gained & lost blocks
```{r}
t_test_dat <- full_data_11_18 %>%
  mutate(dynastic_ward = ifelse(dyn_g_15, "Dynastic Annexation", 
                                ifelse(dyn_l_15, "Dynastic Displacement", NA))) %>%
  filter(!is.na(dynastic_ward), year < 2015)  

  
t_test_dat2 <- full_join(block_demo_10, treat_10, by = "geoid10") %>%
  mutate(dynastic_ward = ifelse(dyn_g_15, "Dynastic Annexation", 
                                ifelse(dyn_l_15, "Dynastic Displacement", NA))) %>%
  filter(!is.na(dynastic_ward))

descr_levels = c("Gain", "Loss")
diff_means1 <- as.data.frame(full_data_11_18 %>%
  mutate(dynastic_ward = ifelse(dyn_g_15, "gain", 
                                ifelse(dyn_l_15, "loss", NA))) %>%
  filter(!is.na(dynastic_ward), year < 2015)  %>%
  group_by(dynastic_ward) %>%
  summarise("Average No. Homicides"  = mean(homicide),
            "Average No. Assaults"  = mean(assault),
            "Average No. Robberies"  = mean(robbery),
            "Average No. Thefts"  = mean(theft),
            "Average No. Potholes Filled"  = mean(pothole_filledD),
            "Average Unemployment Rate of Pop > 18"  = mean(unemp_pct, na.rm = TRUE),
            "Average % w/ College Degree"  = mean(ba_pct, na.rm = TRUE),
            "Median Household Income"  = mean(med_inc, na.rm = TRUE)) %>%
  t()) %>%
  rename(gain = V1, loss = V2) %>%
  filter(gain != "gain") %>%
  mutate(gain= as.numeric(gain),
         loss = as.numeric(loss),
         difference = loss-gain)
 print(xtable( mapply("format", diff_means1, digits=3)))
 
diff_means2 <- as.data.frame(full_join(block_demo_10, treat_10, by = "geoid10") %>%
  mutate(dynastic_ward = ifelse(dyn_g_15, "gain", 
                                ifelse(dyn_l_15, "loss", NA))) %>%
  filter(!is.na(dynastic_ward))  %>%
  group_by(dynastic_ward) %>%
  summarise("Average % Black Residents" = mean(black_pct, na.rm = TRUE),
            "Average % White Residents"  = mean(white_pct, na.rm = TRUE),
            "Average % Hispanic Residents"  = mean(hisp_pct, na.rm = TRUE))  %>%
  t()) %>%
  rename(gain = V1, loss = V2) %>%
  filter(gain != "gain") %>%
  mutate(gain= as.numeric(gain),
         loss = as.numeric(loss),
         difference = loss-gain)
 print(xtable(mapply("format", diff_means2, digits=3)))
 
t.test(black_pct ~ dynastic_ward, data=filter(t_test_dat2, !is.na(black_pct)))
t.test(white_pct ~ dynastic_ward, data=filter(t_test_dat2, !is.na(white_pct)))
t.test(hisp_pct ~ dynastic_ward, data=filter(t_test_dat2, !is.na(hisp_pct)))
t.test(unemp_pct ~ dynastic_ward, data=filter(t_test_dat, !is.na(unemp_pct)))
t.test(ba_pct ~ dynastic_ward, data=filter(t_test_dat, !is.na(ba_pct)))
t.test(med_inc ~ dynastic_ward, data=filter(t_test_dat, !is.na(med_inc)))
t.test(homicide ~ dynastic_ward, data=filter(t_test_dat, !is.na(homicide)))
t.test(assault ~ dynastic_ward, data=filter(t_test_dat, !is.na(assault)))
t.test(robbery ~ dynastic_ward, data=filter(t_test_dat, !is.na(robbery)))
t.test(theft ~ dynastic_ward, data=filter(t_test_dat, !is.na(theft)))
t.test(pothole_filledD ~ dynastic_ward, data=filter(t_test_dat, !is.na(pothole_filledD)))

 
```

# Supplemental Materials

Table A1. Demographic Characteristics of Dynastic vs. Non-Dynastic Wards
```{r}

  

descr_levels = c("Control", "Annexation")
descriptives <- full_data_11_18 %>%
  mutate(dynastic_ward = ifelse(dyn_const, "Dynastic Ward", "Other"),
         match_nonmatch = ifelse(race_match05 ==0 & race_match15 ==1, 1, 0)) %>%
  group_by(dynastic_ward) %>%
  summarise("Average Total Population"  = mean(tot_pop),
            "Average % Black Residents" = mean(black_pct, na.rm = TRUE),
            "Average % White Residents"  = mean(white_pct, na.rm = TRUE),
            "Average % Hispanic Residents"  = mean(hispanic_pct, na.rm = TRUE),
            "Average % Asian Residents"  = mean(asian_pct, na.rm = TRUE),
            "Pct Racial Match, Black Blocks" = mean(black_match)*100,
            "Pct Racial Match, White Blocks" = mean(white_match)*100,
            "Pct Racial Match, Hispanic Blocks" = mean(hisp_match)*100,
            "Average No. Occupied Dwellings"  = mean(occupied),
            "Average Unemployment Rate of Pop > 18"  = mean(unemp_pct, na.rm = TRUE),
            "Average % w/ College Degree"  = mean(ba_pct, na.rm = TRUE),
            "Median Household Income"  = mean(med_inc, na.rm = TRUE),
            "Average % Female Residents"  = mean(femal_pct, na.rm = TRUE),
            "Average % of Pop Over 18"  = mean(pop18_over_pct, na.rm = TRUE)) 
 print(xtable(t( mapply("format", descriptives, digits=1))))

 

 # 6,773 observations where there is no median income data
```

Table A2. Crime & City Services in Dynastic vs. Non-Dynastic Wards 
```{r}


outcome_descripts <- full_data_11_18 %>%
 # filter(const_treat_only != 1) %>%
   mutate(dynastic_ward = ifelse(dyn_const, "Dynastic Ward", "Other")) %>%
  group_by(dynastic_ward) %>%
  summarise("Average No. Homicides"  = mean(homicide),
            "Average No. Assaults"  = mean(assault),
            "Average No. Robberies"  = mean(robbery),
            "Average No. Thefts"  = mean(theft),
            "Average No. Potholes Filled"  = mean(pothole_filledD))
 print(xtable(t( mapply("format", outcome_descripts, digits=3)))) 
 

```

Table A3. OLS Regression of Crime on Block Membership in Dynastic vs. Non-Dynastic Wards
```{r}
stargazer(potholes_ols, homicide_ols, assault_ols, rob_ols, theft_ols,
          star.cutoffs = c(0.05, 0.01, 0.001), omit.stat=c("LL","ser","f"), 
          ci=TRUE, ci.level=0.95, single.row=FALSE,
           covariate.labels = c( "Dynastic Ward", "Total Population", "% Black", "% Hispanic",  "% White" , "% Asian" , 
                              "% Female",  "% Pop Over 18"  ,  "% Unemployed Over 18" , "No. Occupied Buildings" , 
                             "% College Educated" , "Median Income",  
                        "Maj. Black Block Redistricted into Maj. Black Ward " ,  "Maj. Hispanic Block Redistricted into Maj. Hispanic Ward " ,  
                        "Maj. White Block Redistricted into Maj. White Ward" , 
                        "Redistricted in 2015" ),
           add.lines = list( c( "Year FEs", "Yes", "Yes", "Yes", "Yes" , "Yes"),
                             c( "Covariates", "Yes", "Yes", "Yes", "Yes" , "Yes") ),
           omit = c( "nonpop_dummy") )


```

Table A4. TWFE Estimation of Effects of Annexation into Dynastic Wards on City Services (no covariates)
```{r}



potholes_twfe <- felm(pothole_filledD ~ dyn_gain | 
                             year + geoid10 | 0  | geoid10,
                   data = filter(full_data_11_18, dyn_const != 1, dyn_l_15 != 1))

homicide_twfe <- felm(homicide ~ dyn_gain | 
                             year + geoid10 | 0  | geoid10,
                   data = filter(full_data_11_18, dyn_const != 1, dyn_l_15 != 1))

assault_twfe <- felm(assault ~ dyn_gain | 
                             year + geoid10 | 0  | geoid10,
                   data = filter(full_data_11_18, dyn_const != 1, dyn_l_15 != 1))

rob_twfe <- felm(robbery ~ dyn_gain | 
                             year + geoid10 | 0  | geoid10,
                   data = filter(full_data_11_18, dyn_const != 1, dyn_l_15 != 1))

theft_twfe <- felm(theft ~ dyn_gain | 
                             year + geoid10 | 0  | geoid10,
                   data = filter(full_data_11_18, dyn_const != 1, dyn_l_15 != 1))



stargazer(potholes_twfe, homicide_twfe, assault_twfe, rob_twfe, theft_twfe, 
          star.cutoffs = c(0.1, 0.05, 0.001),
          omit.stat=c("LL","ser","f"), ci=TRUE, ci.level=0.95, single.row=FALSE,
          covariate.labels = c("Dynastic Annexation"),
           add.lines = list( c( "Block & Year FEs", "Yes", "Yes", "Yes", "Yes" , "Yes"),
                             c( "Covariates", "No", "No", "No", "No" , "No"),
                             c( "Pre-Trends or Time-Varying Treatment", "No", "No", "No", "No" , "No") ))
```

Table A5. Time-Varying Effects of Annexation into Dynastic Wards on City Services (without covariates, also summarizes wald results)
```{r}



potholes_gain <- felm(pothole_filledD ~ year_2011:dyn_g_15 + year_2012:dyn_g_15 + 
                         year_2013:dyn_g_15 + year_2015:dyn_g_15 + 
                         year_2016:dyn_g_15 + 
                             year_2017:dyn_g_15 + 
                             year_2018:dyn_g_15  | 
                             year + geoid10 | 0  | geoid10,
                   data = filter(full_data_11_18, dyn_const != 1, dyn_l_15 != 1))

homicide_gain <- felm(homicide ~ year_2011:dyn_g_15 + year_2012:dyn_g_15 + 
                         year_2013:dyn_g_15 + year_2015:dyn_g_15 + 
                         year_2016:dyn_g_15 + 
                             year_2017:dyn_g_15 + 
                             year_2018:dyn_g_15  | 
                             year + geoid10 | 0  | geoid10,
                   data = filter(full_data_11_18, dyn_const != 1, dyn_l_15 != 1))

assault_gain <- felm(assault ~ year_2011:dyn_g_15 + year_2012:dyn_g_15 + 
                         year_2013:dyn_g_15 + year_2015:dyn_g_15 + 
                         year_2016:dyn_g_15 + 
                             year_2017:dyn_g_15 + 
                             year_2018:dyn_g_15 | 
                             year + geoid10 | 0  | geoid10,
                   data = filter(full_data_11_18, dyn_const != 1, dyn_l_15 != 1))

rob_gain <- felm(robbery ~ year_2011:dyn_g_15 + year_2012:dyn_g_15 + 
                         year_2013:dyn_g_15 + year_2015:dyn_g_15 + 
                         year_2016:dyn_g_15 + 
                             year_2017:dyn_g_15 + 
                             year_2018:dyn_g_15  | 
                             year + geoid10 | 0  | geoid10,
                   data = filter(full_data_11_18, dyn_const != 1, dyn_l_15 != 1))

theft_gain <- felm(theft ~ year_2011:dyn_g_15 + year_2012:dyn_g_15 + 
                         year_2013:dyn_g_15 + year_2015:dyn_g_15 + 
                         year_2016:dyn_g_15 + 
                             year_2017:dyn_g_15 + 
                             year_2018:dyn_g_15  | 
                             year + geoid10 | 0  | geoid10,
                   data = filter(full_data_11_18, dyn_const != 1, dyn_l_15 != 1))




# wald tests
wald(pot_es1, "year_1::[123]")
wald(hom_es1, "year_1::[123]")
wald(assault_es1, "year_1::[123]")
wald(rob_es1, "year_1::[123]")
wald(theft_es1, "year_1::[123]")


stargazer(potholes_gain, homicide_gain, assault_gain, rob_gain, theft_gain, 
          star.cutoffs = c(0.05, 0.01, 0.001), omit.stat=c("LL","ser","f"), 
          ci=TRUE, ci.level=0.95, single.row=FALSE,
           covariate.labels = c("Annexation x 2011",  "Annexation x 2012", "Annexation x 2013",
                        "Dynasty Effect 2015", "Dynasty Effect 2016", "Dynasty Effect 2017", "Dynasty Effect 2018"),
           add.lines = list( c( "Year & Block FEs", "Yes", "Yes", "Yes", "Yes" , "Yes"),
                             c( "Time-Varying Covariates", "No", "No", "No", "No", "No") ,
                             c( "Evidence of Pre-Trends, based on Wald Test", "No", "No", "No", "No" , "Yes") ))

```

Figure A1. Outcomes over time, by treatment status
```{r}

potholes_descrip <- full_data_11_18 %>%
  filter(dyn_const != 1, dyn_l_15 != 1) %>%
  mutate("Dynastic Annexation" = as.factor(dyn_g_15)) %>%
  group_by(`Dynastic Annexation`, year) %>%
  summarize(pothole_filledD = mean(pothole_filledD, na.rm = TRUE)) %>%
  ggplot(aes(year, pothole_filledD, linetype = `Dynastic Annexation`)) +
  geom_point() +
  geom_line() +
  theme_bw() +
  geom_vline(xintercept = 2015, lty = 3) +
  labs(x = "Year",  y = "Potholes Filled")
ggsave("results_rr_2/potholes_descrip.pdf")

hom_descrip <- full_data_11_18 %>%
  filter(dyn_const != 1, dyn_l_15 != 1) %>%
  mutate("Dynastic Annexation" = as.factor(dyn_g_15)) %>%
  group_by(`Dynastic Annexation`, year) %>%
  summarize(homicide = mean(homicide, na.rm = TRUE)) %>%
  ggplot(aes(year, homicide, linetype = `Dynastic Annexation`)) +
  geom_point() +
  geom_line() +
  theme_bw() +
  geom_vline(xintercept = 2015, lty = 3)+
  labs(x = "Year",  y = "Homicides")
ggsave("results_rr_2/homicides_descrip.pdf")


assault_descrip <- full_data_11_18 %>%
  filter(dyn_const != 1, dyn_l_15 != 1) %>%
  mutate("Dynastic Annexation" = as.factor(dyn_g_15)) %>%
  group_by(`Dynastic Annexation`, year) %>%
  summarize(assault = mean(assault, na.rm = TRUE)) %>%
  ggplot(aes(year, assault, linetype = `Dynastic Annexation`)) +
  geom_point() +
  geom_line() +
  theme_bw() +
  geom_vline(xintercept = 2015, lty = 3)+
  labs(x = "Year",  y = "Robberies")
ggsave("results_rr_2/assaults_descrip.pdf")



rob_descrip <- full_data_11_18 %>%
  filter(dyn_const != 1, dyn_l_15 != 1) %>%
  mutate("Dynastic Annexation" = as.factor(dyn_g_15)) %>%
  group_by(`Dynastic Annexation`, year) %>%
  summarize(robbery = mean(robbery, na.rm = TRUE)) %>%
  ggplot(aes(year, robbery, linetype = `Dynastic Annexation`)) +
  geom_point() +
  geom_line() +
  theme_bw() +
  geom_vline(xintercept = 2015, lty = 3) +
  labs(x = "Year",  y = "Robberies")
ggsave("results_rr_2/robberies_descrip.pdf")



theft_descrip <- full_data_11_18 %>%
  filter(dyn_const != 1, dyn_l_15 != 1) %>%
  mutate("Dynastic Annexation" = as.factor(dyn_g_15)) %>%
  group_by(`Dynastic Annexation`, year) %>%
  summarize(theft = mean(theft, na.rm = TRUE)) %>%
  ggplot(aes(year, theft, linetype = `Dynastic Annexation`)) +
  geom_point() +
  geom_line() +
  theme_bw() +
  geom_vline(xintercept = 2015, lty = 3) +
  labs(x = "Year",  y = "Thefts")
ggsave("results_rr_2/thefts_descrip.pdf")

```


Figure A2. Annexation into Dynastic Wards (with covariates)
```{r}


# SERVICES

pot_es2 = feols(pothole_filledD ~ i(year_1, Annexation, ref = 4) + ## Our key interaction: time × treatment status
		 tot_pop + black_pct + hispanic_pct + white_pct +asian_pct +
                             nonpop_dummy+femal_pct+ occupied + pop18_over_pct  + unemp_pct + 
                        black_match + hisp_match + white_match +
                        redistrict15 + ba_pct + med_inc| 
                             year_1 + geoid10 ,                             ## FEs
		 cluster = ~geoid10,                          ## Clustered SEs
		 data = event_study_data)

pdf("results_rr_2/pot_plot_gain.pdf")
iplot(pot_es2, 
      xlab = 'Year',
      main = '')
dev.off()


hom_es2 = feols(homicide ~ i(year_1, Annexation, ref = 4) + ## Our key interaction: time × treatment status
		  tot_pop + black_pct + hispanic_pct + white_pct +asian_pct +
                             nonpop_dummy+femal_pct+ occupied + pop18_over_pct  + unemp_pct + 
                        black_match + hisp_match + white_match +
                        redistrict15 + ba_pct + med_inc| 
                             year_1 + geoid10 ,                             ## FEs
		 cluster = ~geoid10,                          ## Clustered SEs
		 data = event_study_data)

pdf("results_rr_2/hom_plot_gain.pdf")
hom_es2 %>%
  iplot(xlab = 'Year',
      main = '')
dev.off()


assault_es2 = feols(assault ~ i(year_1, Annexation, ref = 4) + ## Our key interaction: time × treatment status
		  tot_pop + black_pct + hispanic_pct + white_pct +asian_pct +
                             nonpop_dummy+femal_pct+ occupied + pop18_over_pct  + unemp_pct + 
                        black_match + hisp_match + white_match +
                        redistrict15 + ba_pct + med_inc| 
                             year_1 + geoid10 ,                             ## FEs
		 cluster = ~geoid10,                          ## Clustered SEs
		 data = event_study_data)


pdf("results_rr_2/assault_plot_gain.pdf")
iplot(assault_es2, 
      xlab = 'Year',
      main = '')
dev.off()

rob_es2 = feols(robbery ~ i(year_1, Annexation, ref = 4) + ## Our key interaction: time × treatment status
		  tot_pop + black_pct + hispanic_pct + white_pct +asian_pct +
                             nonpop_dummy+femal_pct+ occupied + pop18_over_pct  + unemp_pct + 
                        black_match + hisp_match + white_match +
                        redistrict15 + ba_pct | 
                             year_1 + geoid10 ,                             ## FEs
		 cluster = ~geoid10,                          ## Clustered SEs
		 data = event_study_data)


pdf("results_rr_2/rob_plot_gain.pdf")
iplot(rob_es2, 
      xlab = 'Year',
      main = '')
dev.off()


theft_es2 = feols(theft ~ i(year_1, Annexation, ref = 4) + ## Our key interaction: time × treatment status
		  tot_pop + black_pct + hispanic_pct + white_pct +asian_pct +
                             nonpop_dummy+femal_pct+ occupied + pop18_over_pct  + unemp_pct + 
                        black_match + hisp_match + white_match +
                        redistrict15 + ba_pct + med_inc| 
                             year_1 + geoid10 ,                             ## FEs
		 cluster = ~geoid10,                          ## Clustered SEs
		 data = event_study_data)

pdf("results_rr_2/theft_plot_gain.pdf")
iplot(theft_es2, 
      xlab = 'Year',
      main = '')
dev.off()


```


Table A6. Time-Varying Effects of Annexation into Dynastic Wards on City Services (with covariates)
```{r}



potholes_gain2 <- felm(pothole_filledD ~ year_2011:dyn_g_15 + year_2012:dyn_g_15 + 
                         year_2013:dyn_g_15 + year_2015:dyn_g_15 + 
                         year_2016:dyn_g_15 + 
                             year_2017:dyn_g_15 + 
                             year_2018:dyn_g_15 + tot_pop + black_pct + hispanic_pct + white_pct +asian_pct +
                             nonpop_dummy+femal_pct+  pop18_over_pct  + unemp_pct + occupied + ba_pct + med_inc +
                        black_match + hisp_match + white_match +
                        redistrict15  | 
                             year + geoid10 | 0  | geoid10,
                   data = filter(full_data_11_18, dyn_const != 1, dyn_l_15 != 1))

homicide_gain2 <- felm(homicide ~ year_2011:dyn_g_15 + year_2012:dyn_g_15 + 
                         year_2013:dyn_g_15 + year_2015:dyn_g_15 + 
                         year_2016:dyn_g_15 + 
                             year_2017:dyn_g_15 + 
                             year_2018:dyn_g_15 + tot_pop + black_pct + hispanic_pct + white_pct +asian_pct +
                             nonpop_dummy+femal_pct+  pop18_over_pct  + unemp_pct + occupied + ba_pct + med_inc +
                        black_match + hisp_match + white_match +
                        redistrict15 | 
                             year + geoid10 | 0  | geoid10,
                   data = filter(full_data_11_18, dyn_const != 1, dyn_l_15 != 1))

assault_gain2 <- felm(assault ~ year_2011:dyn_g_15 + year_2012:dyn_g_15 + 
                         year_2013:dyn_g_15 + year_2015:dyn_g_15 + 
                         year_2016:dyn_g_15 + 
                             year_2017:dyn_g_15 + 
                             year_2018:dyn_g_15 + tot_pop + black_pct + hispanic_pct + white_pct +asian_pct +
                             nonpop_dummy+femal_pct+  pop18_over_pct  + unemp_pct + occupied + ba_pct + med_inc +
                        black_match + hisp_match + white_match +
                        redistrict15 | 
                             year + geoid10 | 0  | geoid10,
                   data = filter(full_data_11_18, dyn_const != 1, dyn_l_15 != 1))

rob_gain2 <- felm(robbery ~ year_2011:dyn_g_15 + year_2012:dyn_g_15 + 
                         year_2013:dyn_g_15 + year_2015:dyn_g_15 + 
                         year_2016:dyn_g_15 + 
                             year_2017:dyn_g_15 + 
                             year_2018:dyn_g_15 + tot_pop + black_pct + hispanic_pct + white_pct +asian_pct +
                             nonpop_dummy+femal_pct+  pop18_over_pct  + unemp_pct + occupied + ba_pct + med_inc +
                        black_match + hisp_match + white_match +
                        redistrict15 | 
                             year + geoid10 | 0  | geoid10,
                   data = filter(full_data_11_18, dyn_const != 1, dyn_l_15 != 1))

theft_gain2 <- felm(theft ~ year_2011:dyn_g_15 + year_2012:dyn_g_15 + 
                         year_2013:dyn_g_15 + year_2015:dyn_g_15 + 
                         year_2016:dyn_g_15 + 
                             year_2017:dyn_g_15 + 
                             year_2018:dyn_g_15 + tot_pop + black_pct + hispanic_pct + white_pct +asian_pct +
                             nonpop_dummy+femal_pct+  pop18_over_pct  + unemp_pct + occupied + ba_pct + med_inc +
                        black_match + hisp_match + white_match +
                        redistrict15 | 
                             year + geoid10 | 0  | geoid10,
                   data = filter(full_data_11_18, dyn_const != 1, dyn_l_15 != 1))






# wald tests
wald(pot_es2, "year_1::[123]")
wald(hom_es2, "year_1::[123]")
wald(assault_es2, "year_1::[123]")
wald(rob_es2, "year_1::[123]")
wald(theft_es2, "year_1::[123]")


stargazer(potholes_gain2, homicide_gain2, assault_gain2, rob_gain2, theft_gain2, 
          star.cutoffs = c(0.05, 0.01, 0.001), omit.stat=c("LL","ser","f"), 
          ci=TRUE, ci.level=0.95, single.row=FALSE,
           covariate.labels = c( "Total Population", "% Black", "% Hispanic",  "% White" , "% Asian" , 
                              "% Female",  "% Pop Over 18"  ,  "% Unemployed Over 18" , "No. Occupied Buildings" , 
                             "% College Educated" , "Median Income",  
                        "Maj. Black Block Redistricted into Maj. Black Ward " ,  "Maj. Hispanic Block Redistricted into Maj. Hispanic Ward " ,  
                        "Maj. White Block Redistricted into Maj. White Ward" , 
                        "Redistricted in 2015", "Annexation x 2011",  "Annexation x 2012", "Annexation x 2013",
                        "Dynasty Effect 2015", "Dynasty Effect 2016", "Dynasty Effect 2017", "Dynasty Effect 2018"),
           add.lines = list( c( "Year & Block FEs", "Yes", "Yes", "Yes", "Yes" , "Yes"),
                             c( "Time-Varying Covariates", "Yes", "Yes", "Yes", "Yes" , "Yes") ,
                             c( "Evidence of Pre-Trends, based on Wald Test", "No", "No", "No", "Yes" , "Yes") ),
           omit = c( "nonpop_dummy") )

```

Figure A3. Annexation into Committee Chair Positions (with covariates)
```{r}



# SERVICES

pot_es_commit2 = feols(pothole_filledD ~ i(year_1, Annexation, ref = 4) +
                        tot_pop + black_pct + hispanic_pct + white_pct +asian_pct +
                             nonpop_dummy+femal_pct+ occupied + pop18_over_pct  + unemp_pct + 
                        black_match + hisp_match + white_match +
                        redistrict15 + ba_pct + med_inc | 
                             year_1 + geoid10 ,                             ## FEs
		 cluster = ~geoid10,                          ## Clustered SEs
		 data = event_study_data2)

pdf("results_rr_2/pot_plot_gain_commit_cov.pdf")
iplot(pot_es_commit2, 
      xlab = 'Year',
      main = '')
dev.off()


hom_es_commit2 = feols(homicide ~ i(year_1, Annexation, ref = 4)  +
                        tot_pop + black_pct + hispanic_pct + white_pct +asian_pct +
                             nonpop_dummy+femal_pct+ occupied + pop18_over_pct  + unemp_pct + 
                        black_match + hisp_match + white_match +
                        redistrict15 + ba_pct + med_inc  | 
                             year_1 + geoid10 ,                             ## FEs
		 cluster = ~geoid10,                          ## Clustered SEs
		 data = event_study_data2)

pdf("results_rr_2/hom_plot_gain_commit_cov.pdf")
hom_es_commit2 %>%
  iplot(xlab = 'Year',
      main = '')
dev.off()


assault_es_commit2 = feols(assault ~ i(year_1, Annexation, ref = 4) +
                        tot_pop + black_pct + hispanic_pct + white_pct +asian_pct +
                             nonpop_dummy+femal_pct+ occupied + pop18_over_pct  + unemp_pct + 
                        black_match + hisp_match + white_match +
                        redistrict15 + ba_pct + med_inc  | 
                             year_1 + geoid10 ,                             ## FEs
		 cluster = ~geoid10,                          ## Clustered SEs
		 data = event_study_data2)


pdf("results_rr_2/assault_plot_gain_commit_cov.pdf")
iplot(assault_es_commit2, 
      xlab = 'Year',
      main = '')
dev.off()

rob_es_commit2 = feols(robbery ~ i(year_1, Annexation, ref = 4)  +
                        tot_pop + black_pct + hispanic_pct + white_pct +asian_pct +
                             nonpop_dummy+femal_pct+ occupied + pop18_over_pct  + unemp_pct + 
                        black_match + hisp_match + white_match +
                        redistrict15 + ba_pct + med_inc | 
                             year_1 + geoid10 ,                             ## FEs
		 cluster = ~geoid10,                          ## Clustered SEs
		 data = event_study_data2)


pdf("results_rr_2/rob_plot_gain_commit_cov.pdf")
iplot(rob_es_commit2, 
      xlab = 'Year',
      main = '')
dev.off()


theft_es_commit2 = feols(theft ~ i(year_1, Annexation, ref = 4)  +
                        tot_pop + black_pct + hispanic_pct + white_pct +asian_pct +
                             nonpop_dummy+femal_pct+ occupied + pop18_over_pct  + unemp_pct + 
                        black_match + hisp_match + white_match +
                        redistrict15 + ba_pct + med_inc | 
                             year_1 + geoid10 ,                             ## FEs
		 cluster = ~geoid10,                          ## Clustered SEs
		 data = event_study_data2)

pdf("results_rr_2/theft_plot_gain_commit_cov.pdf")
iplot(theft_es_commit2, 
      xlab = 'Year',
      main = '')
dev.off()


# wald tests
wald(pot_es_commit2, "year_1::[123]")
wald(hom_es_commit2, "year_1::[123]")
wald(assault_es_commit2, "year_1::[123]")
wald(rob_es_commit2, "year_1::[123]")
wald(theft_es_commit2, "year_1::[123]")

```

Table A7. Placebo tests for robberies & thefts
```{r}

placebo_data <- outcome_data %>%
  left_join(treat_10, by = "geoid10") %>%
  left_join(blkgrp2010, by = "geoid10") %>%
  left_join(bgrp_demo_11_18, by =c("geoid_bgrp", "year")) %>%
  left_join(race_match2005, by = "geoid10")%>%
  left_join(race_match2015, by = "geoid10") %>%
  mutate(dyn_gain13 = ifelse(year >= 2013 & dyn_g_15 == 1 & dyn_l_15 != 1, 1, 
                           ifelse(dyn_l_15 ==1, NA, 0)),
         dyn_gain12 = ifelse(year >= 2012 & dyn_g_15 == 1 & dyn_l_15 != 1, 1, 
                           ifelse(dyn_l_15 ==1, NA, 0)),
         redistrict15 = ifelse(year >= 2015 & ward2005 != ward2015, 1, 0),
         dyn_g_15_na = ifelse(dyn_l_15 == 1, NA, 
                            ifelse(dyn_const == 1, NA, dyn_g_15)),
         dyn_l_15_na = ifelse(dyn_g_15 == 1, NA, 
                              ifelse(dyn_const == 1, NA,dyn_l_15)),
         commit_gain = ifelse(year >= 2015 & commit_gain_2015 == 1 & commit_loss_2015 != 1, 1, 
                           ifelse(commit_loss_2015 ==1, NA, 0)),
         commit_g_15_na = ifelse(commit_loss_2015 == 1, NA, 
                            ifelse(commit_const == 1, NA, commit_gain_2015)),
         ward2005 = as.numeric(ward2005),
         ward2015 = as.numeric(ward2015),
         dyn_ward = ifelse(ward2005 %in% c(14, 21, 33, 34, 39, 40) & year <= 2014, 1, 
                           ifelse(ward2015 %in% c(14, 21, 33, 34, 39, 40) & year >= 2015, 1, 0)),
         race_match = ifelse(race_match05 == 1 & year < 2015, 1,
                             ifelse(race_match15 ==1 & year >=2015, 1, 
                                    ifelse(race_match05 == 0 & year < 2015, 0,
                                    ifelse(race_match15 == 0 & year >= 2015, 0, NA)))),
         asian_match = ifelse(asian_match05 == 1 & year < 2015, 1,
                             ifelse(asian_match15 ==1 & year >=2015, 1, 
                                    ifelse(asian_match05 == 0 & year < 2015, 0,
                                    ifelse(asian_match15 == 0 & year >= 2015, 0, NA)))),
         black_match = ifelse(black_match05 == 1 & year < 2015, 1,
                             ifelse(black_match15 ==1 & year >=2015, 1, 
                                    ifelse(black_match05 == 0 & year < 2015, 0,
                                    ifelse(black_match15 == 0 & year >= 2015, 0, NA)))),
         hisp_match = ifelse(hisp_match05 == 1 & year < 2015, 1,
                             ifelse(hisp_match15 ==1 & year >=2015, 1, 
                                    ifelse(hisp_match05 == 0 & year < 2015, 0,
                                    ifelse(hisp_match15 == 0 & year >= 2015, 0, NA)))),
         white_match = ifelse(white_match05 == 1 & year < 2015, 1,
                             ifelse(white_match15 ==1 & year >=2015, 1, 
                                    ifelse(white_match05 == 0 & year < 2015, 0,
                                    ifelse(white_match15 == 0 & year >= 2015, 0, NA)))),
         asian_pct = (asian/tot_pop)*100,
         asian_pct =  ifelse(tot_pop == 0, 0, asian_pct),
         black_pct = (black/tot_pop)*100,
         black_pct =  ifelse(tot_pop == 0, 0, black_pct),
         hispanic_pct = (hispanic/tot_pop)*100,
         hispanic_pct =  ifelse(tot_pop == 0, 0, hispanic_pct),
         white_pct = (white_non_hisp/tot_pop)*100,
         white_pct =  ifelse(tot_pop == 0, 0, white_pct),
         femal_pct = (female/tot_pop)*100,
         femal_pct =  ifelse(tot_pop == 0, 0, femal_pct),
         ba_pct = (ba_or_more/tot_pop)*100,
         ba_pct =  ifelse(tot_pop == 0, 0, ba_pct),
         unemp_pct = (unemployed/pop18_over)*100,
         unemp_pct =  ifelse(pop18_over == 0, 0, unemp_pct),
         pop18_over_pct = (pop18_over/tot_pop)*100,
         pop18_over_pct =  ifelse(tot_pop == 0, 0, pop18_over_pct),
         nonpop_dummy= 0, 
         nonpop_dummy= ifelse(tot_pop==0, 1, nonpop_dummy),
         year_2011 = ifelse(year == 2011, 1, 0),
         year_2012 = ifelse(year == 2012, 1, 0),
         year_2013 = ifelse(year == 2013, 1, 0),
         year_2014 = ifelse(year == 2014, 1, 0),
         year_2015 = ifelse(year == 2015, 1, 0),
         year_2016 = ifelse(year == 2016, 1, 0),
         year_2017 = ifelse(year == 2017, 1, 0),
         year_2018 = ifelse(year == 2018, 1, 0)) %>%
  mutate(const_treat_only = ifelse(dyn_g_15 == 1 & dyn_l_15 == 0, 1, 
                          ifelse(dyn_l_15 == 1 & dyn_g_15 == 0, 1, 
                                 ifelse(dyn_g_15 == 1 & dyn_l_15 == 1, 0, 0)))) %>%
  # filter out blocks that are on the edge of chicago, whose centroids are not in city limits
  filter(!is.na(ward2005), !is.na(ward2015))




rob_placebo_12 <- felm(robbery ~ dyn_gain12  | 
                             year + geoid10 | 0  | geoid10,
                   data = filter(placebo_data, dyn_const != 1, dyn_l_15 != 1))
rob_placebo_13 <- felm(robbery ~ dyn_gain12 | 
                             year + geoid10 | 0  | geoid10,
                   data = filter(placebo_data, dyn_const != 1, dyn_l_15 != 1))

theft_placebo_12 <- felm(theft ~ dyn_gain12 | 
                             year + geoid10 | 0  | geoid10,
                   data = filter(placebo_data, dyn_const != 1, dyn_l_15 != 1))
theft_placebo_13 <- felm(theft ~ dyn_gain12 | 
                             year + geoid10 | 0  | geoid10,
                   data = filter(placebo_data, dyn_const != 1, dyn_l_15 != 1))



stargazer(rob_placebo_12, rob_placebo_13, theft_placebo_12, theft_placebo_13, 
          star.cutoffs = c(0.1, 0.05, 0.001),
          omit.stat=c("LL","ser","f"), ci=TRUE, ci.level=0.95, single.row=FALSE,
          covariate.labels = c("Dynastic Annexation"),
           add.lines = list( c( "Block & Year FEs", "Yes", "Yes", "Yes", "Yes" , "Yes"),
                             c( "Covariates", "No", "No", "No", "No" , "No")))

```

Figure A4. Annexation into Dynastic Wards (leaving out awards where elections changed the leadership)
```{r}

event_study_data <- full_data_11_18 %>%
  filter(dyn_const != 1, dyn_l_15 != 1, dyn_change != 1) %>%
  mutate(year_1 = year-2010) %>%
  rename(Year = year, Annexation = dyn_g_15)

# SERVICES

pot_es1 = feols(pothole_filledD ~ i(year_1, Annexation, ref = 4) | 
                             year_1 + geoid10 ,                             ## FEs
		 cluster = ~geoid10,                          ## Clustered SEs
		 data = event_study_data)

pdf("results_rr_2/pot_plot_gain_a4.pdf")
iplot(pot_es1, 
      xlab = 'Year',
      main = '')
dev.off()


hom_es1 = feols(homicide ~ i(year_1, Annexation, ref = 4) | 
                             year_1 + geoid10 ,                             ## FEs
		 cluster = ~geoid10,                          ## Clustered SEs
		 data = event_study_data)

pdf("results_rr_2/hom_plot_gain_a4.pdf")
hom_es1 %>%
  iplot(xlab = 'Year',
      main = '')
dev.off()


assault_es1 = feols(assault ~ i(year_1, Annexation, ref = 4)| 
                             year_1 + geoid10 ,                             ## FEs
		 cluster = ~geoid10,                          ## Clustered SEs
		 data = event_study_data)


pdf("results_rr_2/assault_plot_gain_a4.pdf")
iplot(assault_es1, 
      xlab = 'Year',
      main = '')
#ev.off()

rob_es1 = feols(robbery ~ i(year_1, Annexation, ref = 4)| 
                             year_1 + geoid10 ,                             ## FEs
		 cluster = ~geoid10,                          ## Clustered SEs
		 data = event_study_data)


pdf("results_rr_2/rob_plot_gain_a4.pdf")
iplot(rob_es1, 
      xlab = 'Year',
      main = '')
dev.off()


theft_es1 = feols(theft ~ i(year_1, Annexation, ref = 4) | 
                             year_1 + geoid10 ,                             ## FEs
		 cluster = ~geoid10,                          ## Clustered SEs
		 data = event_study_data)

pdf("results_rr_2/theft_plot_gain_a4.pdf")
iplot(theft_es1, 
      xlab = 'Year',
      main = '')
dev.off()



```
 

